<template>
	<view class="">
		<view class="page bg-white b_y">
			<view class="shop">
				<image :src="item.pic" mode="aspectFill"></image>
				<view style="margin: 40rpx;">
					<text style="font-weight:bold;font-size: 40rpx;">{{item.name}}</text>
					<text>{{item.createDate}}</text>
				</view>
				<image v-if="item.platform==1" style="width: 50rpx;height: 50rpx;" src="@/static/tab/mt.png"></image>
				<image v-if="item.platform==2" style="width: 50rpx;height: 50rpx;" src="@/static/tab/elm.png"></image>
			</view>

			<!-- 用户展示活动要求等相关信息 -->
			<view v-if="type==1">
				<view class="bg-white p20 a-c bb">
					<text class="f28 c_z" style="font-weight: bold;font-size: 40rpx;">【活动要求】</text>
					<view class="sm">
						一张订单图，一张品鉴图，一张评价图（30+字评价）
					</view>
				</view>
				<view class="bg-white p20 a-c bb">
					<text class="f28 c_z" style="font-weight: bold;font-size: 40rpx;">【注意事项】</text>
					<view class="sm">
						文字内容要与餐品相关，不可复制粘贴、叠词、内容敷衍，否则将被拉黑，照片要拍摄到手餐品，不可缺图少图、使用不相关的照片。品鉴不合格扣除3片花瓣。
					</view>
				</view>
			</view>
			<!-- 用户展示相关订单信息 -->
			<view v-if="type==2">
				<view class="f-d  bg-white p20 a-c bb">
					<text class="f28 c_z" style="font-weight: bold;font-size: 40rpx;">【订单信息】</text>
				</view>
				<view class="p20">下单时间:{{item.createDate}}</view>
			</view>
			<view class="f-d  bg-white p20 a-c bb">
				<text class="f28 c_z fw">{{type==1?'请上传(好评&商品)截图':'好评截图'}}</text>
			</view>
			<view class="flex" v-if="type==1">
				<image class="b_y" style="height: 208rpx;width:208rpx;" @click="imgview('../../static/fx.jpg')" src="../../static/fx.jpg" mode="aspectFill"></image>
				<view class="uni-uploader__input-box a-c j-c " style="margin-left: 20rpx;" v-if="show">
					<image class="b_y" style="height: 208rpx;width:208rpx;" :src="imageUrl1" mode="aspectFill"></image>
				</view>
				<view style="margin-left: 20rpx;" @tap="on_img(1)" v-if="!show">
					<view class="flex a-c j-c" style="width: 200rpx;height: 200rpx;border: solid 2rpx #bfbfbf; ">
						<text class="bicon" style="font-size: 80rpx;color: #bfbfbf;">&#xe7dd;</text>
					</view>
				</view>
			</view>
			<!-- 示例图片 -->
			<image class="images" :src="item.pica" mode="aspectFill" @click="imgview(item.pica)" v-if="type==2"></image>
			<view class="f-d  bg-white p20 a-c bb">
				<text class="f28 c_z  fw">{{type==1?'请上传订单截图':'订单截图'}}</text>
			</view>
			<view class="flex" v-if="type==1">
				<!-- 示例图片 -->
				<image class="b_y" style="height: 208rpx;width:208rpx;" @click="imgview('../../static/fx.jpg')" src="../../static/fx.jpg" mode="aspectFill"></image>
				<view class="uni-uploader__input-box a-c j-c " style="margin-left: 20rpx;" v-if="show1">
					<image class="b_y" style="height: 208rpx;width:208rpx;" :src="imageUrl2" mode="aspectFill"></image>
				</view>
			<view style="margin-left: 20rpx;" @tap="on_img(2)" v-if="!show1">
					<view class="flex a-c j-c" style="width: 200rpx;height: 200rpx;border: solid 2rpx #bfbfbf;">
						<text class="bicon" style="font-size: 80rpx;color: #bfbfbf;">&#xe7dd;</text>
					</view>
				</view>
			</view>
			<image class="images" :src="item.picb" mode="aspectFill" @click="imgview(item.picb)" v-if="type==2"></image>
		</view>
		<view class="flex j-c a-c">
			<button class="js-image-a" type="default" v-if="type==1"
				style="margin:60rpx 20rpx 80rpx;background-color: #0071FE;width: 600rpx;color: #fff;border-radius: 45rpx;"
				@tap="on_post()">
				<text class=" p20">提交审核</text>
			</button>
			<view class="shbutton" v-if="type==2">
				<button class="js-image-a" type="default " style="margin: 20upx;background-color: #e2e2e2;" @tap="sh(3)">
					<text class=" p20">不通过</text>
				</button>
				<button class="js-image-a" type="default " style="margin: 20upx;background-color: #0071FE;" @tap="sh(2)">
					<text class=" p20" style="color: #fff;">通过</text>
				</button>
			</view>
		</view>
	</view>

	</view>
</template>

<script>
	import $H from '@/common/free-lib/request.js';
	// import choose from "@/common/image/choose.vue"
	// import compress from "@/common/image/compress.vue"
	import $http from '@/common/requestConfig';
	// import avatar from "@/common/yq-avatar/yq-avatar.vue";
	// import LbPicker from '@/common/lb-picker';
	import {
		params
	} from '@/common/time_list.js';
	import Url from "@/common/free-lib/config.js";

	export default {
		name: 'newsPublish',
		components: {
			// choose,
			// avatar,
			// compress,
			// LbPicker,
		},
		data() {
			return {
				type: '',
				imageUrl1: '',
				imageUrl2: '',
				show: false,
				show1: false,
				img_list: [],
				list: [],
				item: {},
			}
		},
		onShow(e) {
			// 判断是否登录
			this.$module.ifToken(res => {
				if (res == 1) {
					this.$module.navigateTo('/pages/banmi/user_login')
				} else {
					return
				}
			})
		},
		onLoad(e) {
			this.type = e.type
			this.item = JSON.parse(e.item)
			this.item.id = this.item.orderId
		},
		methods: {
			on_img(i) {
				this.$module.showLoading('上传中')
				var that = this;
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album'],
					success: res => {
						uni.uploadFile({
							url: Url.baseUrl + '/mehrb/nffw/oss/upload', //上传地址
							filePath: res.tempFilePaths[0],
							name: 'file',
							header: {
								'token': uni.getStorageSync('Token'),
							},
							formData: {
								module: "jpeg", //图片类型
							},
							success: function(res) {
								uni.hideLoading()
								let arr = JSON.parse(res.data);
								that.show = true;
								if (i == 1) {
									that.show = true;
									that.imageUrl1 = arr.data.src;
									that.item.pica = arr.data.src
								} else if (i == 2) {
									that.show1 = true;
									that.imageUrl2 = arr.data.src;
									that.item.picb = arr.data.src
								}
							},
							fail: function(error) {
								uni.hideLoading()
								that.$module.showToast('上传失败!')
							}
						})
					},
					fail: function(error) {
						uni.hideLoading()
						that.$module.showToast('取消上传')
					}
				});
			},
			imgview(url) {
				uni.previewImage({
					urls: [url],
					current: 0
				});
			},
			on_post() { //入驻店铺
				if (!this.item.pica) {
					this.$module.showToast("请上传好评截图")
					return
				} else if (!this.item.pica) {
					this.$module.showToast("请上传订单截图")
				} else {
					this.add_shop()
				}
			},
			// time(picker) {
			// 	this.business_time = picker.value.join("-");
			// },
			add_shop() { //用户提交审核
				this.$module.showLoading('提交中')
				const that = this
				let date = {
					data: ''
				}
				this.$module.sm(that.item, 1, res => {
					date.data = res
				})
				this.Htpp.post('/mehrb/meplus/order/update', 'app', {
					token: true,
					datalist: date
				}).then(ret => {
					this.$module.sm(ret, 2, res => {
						if (res.code == 0) {
							uni.setStorageSync('business', res.data.business)
							that.$module.switchTab('/pages/views/order')
						}
					})
				})
			},
			shs(i) {
				const that = this
				that.item.state = i
				that.$module.showLoading('提交中...')
				let date = {
					data: ''
				}
				that.$module.sm(that.item, 1, res => {
					date.data = res
				})
				that.Htpp.post('/mehrb/meplus/order/busExamine', 'app', {
					token: true,
					datalist: date
				}).then(ret => {
					that.$module.sm(ret, 2, res => {
						if (res.code == 0) {
							that.$module.showToast('提交成功')
							let time = setTimeout(function() {
								that.$module.switchTab('/pages/views/order')
								clearTimeout(time)
							}, 1600);
						}
					})
				})
			},
			sh(i) { //入驻调用接口
				const that = this
				if (i == 2) {
					uni.showModal({
						title: '',
						content: '是否确认' + (i == 2 ? '通过' : '不通过') + '审核?',
						confirmText: '是',
						success: function(res) {
							if (res.confirm) {
								that.shs(i)
							}
						}
					});
				} else if (i == 3) {
					uni.showModal({
						title: '请填写不通过原因',
						content: '',
						editable: true, //是否显示输入框
						placeholderText: '请输入原因', //输入框提示内容、
						confirmText: '确认',
						cancelText: '取消',
						success: (res) => {
							if (res.confirm) {
								that.item.reason = res.content
								that.shs(i)
							}
						}
					});
				}
			},
		}
	}
</script>
<style lang="less">
	.shop {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 10rpx 30rpx;
		padding: 20rpx;
		background-color: #fff;

		image {
			width: 160rpx;
			height: 160rpx;
			border-radius: 10rpx;
		}

		view {
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			margin-left: 10rpx;
		}
	}

	.sm {
		margin: 20rpx;
	}

	.fw {
		font-weight: bold;
	}

	.images {
		display: block;
		margin: 0 auto;
	}

	.shbutton {
		width: 90%;
		position: fixed;
		bottom: 120rpx;
		display: flex;
		justify-content: space-around;

		.button {
			width: 100%;
			color: #fff;
			border-radius: 20rpx;
		}
	}

	page {
		background-color: #fff;
		height: 100vh;
	}

	.shuru {
		height: 250rpx;
		line-height: 50upx;
		width: 750rpx;
		border-width: 2rpx !important;
		border-right-style: solid !important;
		border-left-color: #FFFFFF !important;
		border-right-color: #FFFFFF !important;
		border-bottom-color: #D9D9D9 !important;
		border-top-color: #FFFFFF !important;
	}

	.input-view {
		font-size: 28upx;
	}

	.choose-location {
		padding: 30rpx;
	}

	.info-box {
		padding: 30rpx 0;
	}

	.info-box-item {
		padding-bottom: 20rpx;
	}

	.feedback-title {
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		padding: 20upx;
		color: #8f8f94;
		font-size: 28upx;
	}

	.in {
		width: 500rpx;
		height: 50rpx;
	}

	.close-view {
		width: 35rpx;
		height: 35rpx;
		border-radius: 50%;
		background-color: #FF5053;
		color: #FFFFFF;
		position: relative;
		top: -110px;
		right: -85px;
		font-size: 20rpx;
	}
</style>